package com.crm.system.controller.companyInvoiceManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.dto.CompanyInvoiceDTO;
import com.crm.model.entity.companyInvoiceManager.SysCompanyInvoice;
import com.crm.model.qo.returnMoney.ReturnMoneyQO;
import com.crm.model.vo.companyInvoiceManager.CompanyInvoiceListPageVO;
import com.crm.model.vo.companyInvoiceManager.CompanyInvoiceVO;
import com.crm.system.service.companyInvoiceManager.CompanyInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/4/26 10:14
 */
@RestController
@RequestMapping("/companyInvoice")
public class CompanyInvoiceController {

    @Autowired
    private CompanyInvoiceService companyInvoiceService;

    /**
     * 根据当前登录人公司获取该公司可以选择开发票的公司列表
     * @return
     */
    @GetMapping("/getCompanyListByCompanyId")
    private DataResponse getCompanyListByCompanyId(){
        List<CompanyInvoiceVO> list =companyInvoiceService.getCompanyListByCompanyId();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
    }

    /**
     * 税盘管理列表
     * @return
     */
    @GetMapping("/getCompanyList")
    private DataResponse getCompanyList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                        @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                        @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                        @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                        String companyName//公司名称
    ){
        DhPageInfo<CompanyInvoiceListPageVO> list =companyInvoiceService.getCompanyList(pageIndex,pageSize,sortName,sortOrder,companyName);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
    }

    /**
     * 删除税盘
     * @param companyId  ---公司id
     * @Author chaifuyou
     * @return
     */
    @PostMapping("/delTaxDisc")
    public DataResponse delTaxDisc(HttpServletRequest request, @RequestParam(value="companyId")String companyId){
        companyInvoiceService.delTaxDisc(companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 添加税盘
     * @param sysCompanyInvoice
     * @Author chaifuyou
     * @return
     */
    @PostMapping("/saveTaxDisc")
    public DataResponse saveTaxDisc(HttpServletRequest request, @RequestBody CompanyInvoiceDTO sysCompanyInvoice){
        boolean b =companyInvoiceService.saveTaxDisc(sysCompanyInvoice);
        if (!b){
            return new DhResponse(ResponseCodeEnum.COMPANY_INVOICE_EDITED.getResponseCode());
        }
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 修改税盘
     * @param sysCompanyInvoice
     * @Author chaifuyou
     * @return
     */
    @PostMapping("/updateTaxDisc")
    public DataResponse updateTaxDisc(HttpServletRequest request, @RequestBody CompanyInvoiceDTO sysCompanyInvoice){
        companyInvoiceService.updateTaxDisc(sysCompanyInvoice);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

}
